package peng.yang.express.Adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import peng.yang.express.Interface.OnPagerClickListener;

/**
 * 引导页图片适配器
 * Created by Administrator on 2016/6/24.
 */
public class ImageViewPagerGuidAdapter extends PagerAdapter {

    private Context context;

    private ArrayList<View> ViewList;
    private OnPagerClickListener pagerClickListener;

    public ImageViewPagerGuidAdapter(Context context, ArrayList<View> ViewList, OnPagerClickListener pagerClickListener) {
        this.context = context;
        this.ViewList = ViewList;
        this.pagerClickListener = pagerClickListener;
    }

    @Override
    public int getCount() {
        return ViewList.size();
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View view = ViewList.get(position);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (pagerClickListener != null) {
                    pagerClickListener.onPageClick(context, position);
                }
            }
        });
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(ViewList.get(position));
    }
}
